# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 16:03
# @Author  : 魏福齐
# @Email   : 775776913@qq.com
# @File    : page_caiwu_ysk.py
# @Software: PyCharm

from pages.base_page import BasePage
from selenium.webdriver.common.by import By

class CaiwuPageYsk(BasePage):
    '''应付款页面'''
    add_ysk_submit_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > div.pull-right > '
                                              'a:nth-child(1)')
    #添加应收款按钮
    ysk_name_input_locator = (By.CSS_SELECTOR, '#name')
    #应收款名输入框
    hetong_input_locator = (By.CSS_SELECTOR, '#contract_name')
    #合同输入框
    hetong_tbody_locator = (By.CSS_SELECTOR, '#data')
    #合同选择table的tbody
    hetong_table_ok_locator = (By.CSS_SELECTOR,
                               'body > div:nth-child(9) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix'
                               ' > div > button:nth-child(1) > span')
    #选中合同后的【ok】按钮
    fuzeren_input_locator = (By.CSS_SELECTOR, '#owner_name')
    #负责人输入框
    fuzeren_tbody_locator = (By.CSS_SELECTOR, '#d_content')
    #选择负责人table的tbody
    fuzeren_table_ok_locator = (By.CSS_SELECTOR,
                                'body > div:nth-child(10) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix'
                                ' > div > button:nth-child(1) > span')
    # 选中负责人后的【ok】按钮
    shoukuan_price_input_locator = (By.CSS_SELECTOR, '#price')
    #收款金额输入框
    pay_time_input_locator = (By.CSS_SELECTOR, '#pay_time')
    #收款时间输入框
    miaoshu_input_locator = (By.CSS_SELECTOR,
                             'body > div.container > div.row > div > form > table > tbody > tr:nth-child(9) > '
                             'td:nth-child(2) > textarea')
    #描述输入框
    save_locator = (By.CSS_SELECTOR,
                    'body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) '
                    '> input:nth-child(1)')
    #【保存】应收款按钮
    jump_ysk_locator=(By.CSS_SELECTOR,'body > div.container > div.page-header > ul > li:nth-child(1) > a')
    #回到应收款列表页面
    ysk_lst_name_table_locator=(By.CSS_SELECTOR,'#form1 > table > tbody')
    #应收款列表tbody
    shanchu_submit_locator=(By.CSS_SELECTOR,'#delete')
    #【删除】按钮
    huishou_ysk_locator=(By.CSS_SELECTOR,'#check_all')
    #回收站勾选框
    huishouzhan_submit_locaor=(By.CSS_SELECTOR,'body > div.container > p > a:nth-child(18)')
    #回收站按钮
    shanchu_chenggong_text=(By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')

    def add_ysk(self):
        '''点击【添加应收款】'''
        self.driver.find_element(*self.add_ysk_submit_locator).click()

    def ysk_name_input(self,yskname):
        '''输入应收款名'''
        self.driver.find_element(*self.ysk_name_input_locator).send_keys(yskname)

    def ysk_hetong_check(self,hetong):
        '''选择合同'''
        self.driver.find_element(*self.hetong_input_locator).click()
        # 点击合同选择框
        table = self.driver.find_element(*self.hetong_tbody_locator)
        # 获取合同table
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[3].text == hetong:
                tds[0].find_element(By.TAG_NAME, 'input').click()
                # 选中合同
        self.driver.find_element(*self.hetong_table_ok_locator).click()
        # 点击【ok】

    def ysk_fuzeren_check(self,fuzeren):
        '''选择负责人'''
        self.driver.find_element(*self.fuzeren_input_locator).click()
        # 点击负责人选择框
        table = self.driver.find_element(*self.fuzeren_tbody_locator)
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == fuzeren:
                tds[0].find_element(By.TAG_NAME, 'input').click()
        # 选中负责人
        self.driver.find_element(*self.fuzeren_table_ok_locator).click()
        # 点击【ok】

    def ysk_price_input(self,price):
        '''输入应收款金额'''
        self.driver.find_element(*self.shoukuan_price_input_locator).clear()
        # 清空金额
        self.driver.find_element(*self.shoukuan_price_input_locator).send_keys(price)
        # 输入应收款金额

    def ysk_time_input(self,time):
        '''输入收款时间'''
        self.driver.find_element(*self.pay_time_input_locator).send_keys(time)

    def ysk_miaoshu(self,miaoshu):
        '''输入应收款描述'''
        self.driver.find_element(*self.miaoshu_input_locator).send_keys(miaoshu)

    def save(self):
        '''点击【保存】按钮'''
        self.driver.find_element(*self.save_locator).click()

    def ysk_lst_name_duanyan(self):
        '''获取添加的应收款名'''
        table = self.driver.find_element(*self.ysk_lst_name_table_locator)
        # 获取应收款列表
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            return tds[1].text

    def skd_ysk_name_duanyan(self):
        '''获取应收款状态'''
        table = self.driver.find_element(*self.ysk_lst_name_table_locator)
        # 获取应收款列表
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            return tds[6].text

    def ysk_lst_update(self):
        '''修改已存在的应收款'''
        table = self.driver.find_element(*self.ysk_lst_name_table_locator)
        # 获取应收款列表
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == '高级香水':
                tds[-1].find_element(By.LINK_TEXT, '修改').click()
                break

    def ysk_update_name(self,name):
        '''修改应收款名'''
        self.driver.find_element(*self.ysk_name_input_locator).clear()
        # 清空应收款名
        self.driver.find_element(*self.ysk_name_input_locator).send_keys(name)
        #输入应收款名

    def ysk_update_price(self,price):
        '''修改应收款金额'''
        self.driver.find_element(*self.shoukuan_price_input_locator).clear()
        # 清空收款金额
        self.driver.find_element(*self.shoukuan_price_input_locator).send_keys(price)
        # 输入应收款金额

    def ysk_lst_del(self,yskname):
        '''勾选要删除的应收款 '''
        table = self.driver.find_element(*self.ysk_lst_name_table_locator)
        # 获取应收款列表
        trs = table.find_elements(By.TAG_NAME, 'tr')
        for tr in trs:
            tds = tr.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == yskname:
                tds[0].find_element(By.TAG_NAME, 'input').click()

    def shanchu_submit(self):
        '''点击删除【按钮】'''
        self.driver.find_element(*self.shanchu_submit_locator).click()

    def shanchu_accept(self):
        '''点击警告框的确定'''
        self.driver.switch_to.alert.accept()

    def ysk_huishouzhan_submit(self):
        '''点击回收站'''
        self.driver.find_element(*self.huishouzhan_submit_locaor).click()

    def huishouzhan_gouxuan(self):
        '''勾选所有回收站应收款'''
        self.driver.find_element(*self.huishou_ysk_locator).click()

    def huishou_duanyan(self):
        '''获取回收站删除成功的文本'''
        return self.driver.find_element(*self.shanchu_chenggong_text).text




